//
//  NewsDetailViewController.m
//  pushNewsManager
//
//  Created by Jobs on 7/31/17.
//  Copyright © 2017 com.Iori. All rights reserved.
//

#import "NewsDetailViewController.h"
//#import "UINavigationController+Autorotate.h"
#import "PECropViewController.h"
#import "UIView+Screenshot.h"
#import "Header.h"
#import "DeleteArtApi.h"
#import "ViewController.h"
#import "SetArtApproveStatusApi.h"
#import "UploadNewsImageApi.h"
#import "SetArtImgApi.h"
#import "SetArtTimeApi.h"
#import "SetArtHotApi.h"
#import "SetArtDescApi.h"
#import "SDWebImageManager.h"
#import "NewsCategoryManagerViewController.h"
#import "EndEditArtApi.h"
#import "ChooseHotViewController.h"
#import "SetArtFromApi.h"
#import "ChannelListEntity.h"
#import "SetArtIndexApi.h"
#import "SetArtChannelApi.h"
#import "HotSpotEntity.h"
#import "ChooseHotSpotViewController.h"
#import "UpdateArtApi.h"

@interface NewsDetailViewController () <PECropViewControllerDelegate, chooseHotSpot_protocol, NewsCategoryUpdateProtocol>
{
}
@property (nonatomic, assign) NSInteger iPicCount;
@property (weak, nonatomic) IBOutlet UIScrollView *picScrollView;
@property (weak, nonatomic) IBOutlet UIButton *btnAddPic;
@property (strong, nonatomic) NSMutableArray<UIImage*> *arrayPic;
@property (strong, nonatomic) NSMutableArray<UIButton*> *arrayBtnItem;
@property (strong, nonatomic) NSMutableArray<NSString*> *arrayImageName;
@property (copy, nonatomic) NSString *publictime;
@property (weak, nonatomic) IBOutlet UITextField *txtFrom;
@property (copy, nonatomic) NSString *selectedChannelID;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *txtViewTitleHeightConstraint;
@property (weak, nonatomic) IBOutlet UITextView *txtViewTitle;
@property (copy, nonatomic) NSString *hot;
@property (assign, nonatomic) BOOL isShowInHome;
@end

@implementation NewsDetailViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    WS(weakSelf);
    self.isShowInHome = YES;
    NSURL *url = [NSURL URLWithString:self.news.art_url];
    [self.webView loadRequest:[NSURLRequest requestWithURL:url]];
    self.picScrollView.contentSize = CGSizeMake(70*4+3*4, self.picScrollView.frame.size.height);
    self.arrayPic = [NSMutableArray arrayWithCapacity:4];
    self.arrayBtnItem = [NSMutableArray arrayWithCapacity:4];
    self.arrayImageName = [NSMutableArray arrayWithCapacity:4];
    self.txtDesc.text = self.news.art_desc;
    self.txtFrom.text = self.news.art_from;
    self.txtViewTitle.text = self.news.art_title;
    //NSDateFormatter *formater = [NSDateFormatter dateFormatterWithFormat:@"yyyy-MM-dd HH:mm:ss"];
    weakSelf.publictime = self.news.art_show_time;//[formater stringFromDate:[NSDate date]];
    if([self.news.art_index isEqualToString:@"1"] || self.news.art_id == nil)
    {
        [self.radHome setSelected:YES];
    }
    self.selectedChannelID = self.news.channel_id;
    self.hot = self.news.hot_id;
    if(self.news.art_img.count > 0)
    {
        NSMutableArray<UIImage*> *arrayImage = [NSMutableArray arrayWithCapacity:4];
        [self.news.art_img enumerateObjectsUsingBlock:^(NSDictionary*  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop)
        {
            [arrayImage addObject:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:(NSString*)[obj objectForKey:@"path"]]]]];
            [weakSelf.arrayImageName addObject:[obj objectForKey:@"path"]];
        }];
        self.arrayPic = arrayImage;
        [self btnPicItem_click:nil];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
    if([segue.identifier isEqualToString:@"segueHot"])
    {
        ChooseHotSpotViewController *vc = segue.destinationViewController;
        vc.chooseHotSpotDelegate = self;
    }
}


-(UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleDefault;
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}

#pragma mark - PECropViewControllerDelegate methods -

- (void)cropViewController:(PECropViewController *)controller didFinishCroppingImage:(UIImage *)croppedImage transform:(CGAffineTransform)transform cropRect:(CGRect)cropRect
{

    WS(weakSelf);
    [MessageBox displayLoadingInView:weakSelf.view];

    UploadNewsImageApi *api = [UploadNewsImageApi new];
    api.member_id = [UserInfo sharedUser].admin.admin_id;
    api.image = croppedImage;
    [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        [MessageBox removeLoading];
        if([IoriJsonHelper getErrorCode:request] == 100)
        {
            [weakSelf.arrayImageName addObject:[IoriJsonHelper getStringForKey:@"real_path" fromDict:request.responseJSONObject]];
            [controller dismissViewControllerAnimated:YES completion:NULL];
            [weakSelf.arrayPic addObject:croppedImage];
            [weakSelf btnPicItem_click:nil];
            
            if(weakSelf.arrayPic.count == 4) weakSelf.btnAddPic.enabled = NO;
        }
        else
        {
            [MessageBox showMsg:[IoriJsonHelper getError:request] viewController:weakSelf];
        }
    } failure:^(YTKBaseRequest *request) {
        [MessageBox removeLoading];
        [weakSelf showMessage:[request responseString]];
    }];
    
    
}

- (void)cropViewControllerDidCancel:(PECropViewController *)controller
{
    [controller dismissViewControllerAnimated:YES completion:NULL];
}

#pragma mark - choosehotspot protocol -
-(void)chooseHotSpot:(NSArray<HotSpotEntity *> *)arrayChoosed
{
    WS(weakSelf);
    if(arrayChoosed.count == 0) return;
    self.hot = arrayChoosed.firstObject.value;
    if(self.news.art_id == nil)
    {
        return;
    }
    SetArtHotApi *api = [SetArtHotApi new];
    api.admin_id = [UserInfo sharedUser].admin.admin_id;
    api.hot_id = arrayChoosed.firstObject.value;
    api.art_id = self.news.art_id;
    [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        if([IoriJsonHelper getErrorCode:request] == 100)
        {
            //[weakSelf showMessage:[@"设置成功，热点：" stringByAppendingString:arrayChoosed.firstObject.name]];
        }
        else
        {
            [weakSelf showMessage:[IoriJsonHelper getError:request]];
        }
    } failure:^(YTKBaseRequest *request) {
        [weakSelf showMessage:[request responseString]];
    }];
}

-(NSString*)getChooseHotID
{
    return self.hot;
}

#pragma mark - downlist -
//-(void)dropDown_selected:(NSString *)val text:(NSString *)title
//{
//    WS(weakSelf);
//    SetArtHotApi *api = [SetArtHotApi new];
//    api.admin_id = [UserInfo sharedUser].admin.admin_id;
//    api.hot_id = val;
//    api.art_id = self.news.art_id;
//    [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
//        if([IoriJsonHelper getErrorCode:request] == 100)
//        {
//            
//        }
//        else
//        {
//            [weakSelf showMessage:[IoriJsonHelper getError:request]];
//        }
//    } failure:^(YTKBaseRequest *request) {
//        [weakSelf showMessage:[request description]];
//    }];
//}

#pragma mark - newscategory delegate -

-(void)newsCategorySelected:(NSArray<ChannelEntity *> *)arraySelected
{
    NSMutableArray<NSString*> *array = [NSMutableArray arrayWithCapacity:4];
    [arraySelected enumerateObjectsUsingBlock:^(ChannelEntity * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [array addObject:obj.channel_id];
    }];
    self.selectedChannelID = [array componentsJoinedByString:@","];
    if(array.count > 0 && self.news.art_id != nil)
    {
        SetArtChannelApi *api = [SetArtChannelApi new];
        api.admin_id = [UserInfo sharedUser].admin.admin_id;
        api.art_id = self.news.art_id;
        api.channel_id = self.selectedChannelID;
        WS(weakSelf);
        [MessageBox displayLoadingInView:weakSelf.view];
        [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
            [MessageBox removeLoading];
            if([IoriJsonHelper getErrorCode:request] == 100)
            {
                //[weakSelf showMessage:@"设置频道成功"];
            }
            else
            {
                [weakSelf showMessage:[IoriJsonHelper getError:request]];
            }
        } failure:^(YTKBaseRequest *request) {
           [weakSelf showMessage:[request responseString]];
            [MessageBox removeLoading];
        }];
    }
}

-(NSString *)getAleadySelectedChannelID
{
    return self.selectedChannelID;
}

#pragma mark - action -

-(void)endEditStatus
{
    if(self.news.art_id == nil)
    {
        return;
    }
    EndEditArtApi *api  = [EndEditArtApi new];
    api.admin_id = [UserInfo sharedUser].admin.admin_id;
    api.art_id = self.news.art_id;
    WS(weakSelf);
    [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        
        if([IoriJsonHelper getErrorCode:request] == 100)
        {
        }
        else
        {
            [weakSelf showMessage:[IoriJsonHelper getError:request] ];
        }
    } failure:^(YTKBaseRequest *request) {
        [weakSelf showMessage:[request responseString]];
    }];
    
}

-(void)btnPicItem_click:(UIButton*)sender
{
    self.iPicCount = 0;
    if(sender != nil)
    {
        [self.arrayPic removeObjectAtIndex:sender.tag];
        [self.arrayBtnItem enumerateObjectsUsingBlock:^(UIButton * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            [obj removeFromSuperview];
        }];
        [self.arrayBtnItem removeAllObjects];
    }
    [self.arrayPic enumerateObjectsUsingBlock:^(UIImage * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        UIButton *btnItem = [UIButton buttonWithType:UIButtonTypeCustom];
        [btnItem setImage:obj forState:UIControlStateNormal];
        btnItem.frame = CGRectMake((self.iPicCount*70)+4*self.iPicCount, 0, 70, self.picScrollView.frame.size.height);
        btnItem.tag = self.iPicCount;
        [self.picScrollView addSubview:btnItem];
        [self.arrayBtnItem addObject:btnItem];
        self.iPicCount++;
        [btnItem addTarget:self action:@selector(btnPicItem_click:) forControlEvents:UIControlEventTouchUpInside];
    }];
    if(self.iPicCount == 4) self.btnAddPic.enabled = NO;
    else self.btnAddPic.enabled = YES;
}

- (IBAction)btnDelete_click:(UIButton *)sender
{
    WS(weakSelf);
    if(self.news.art_id == nil)
    {
        [self showMessage:@"该新闻还未发布，不能删除。"];
        return;
    }
    DeleteArtApi *api = [DeleteArtApi new];
    api.admin_id = [UserInfo sharedUser].admin.admin_id;
    api.art_id = self.news.art_id;
    [MessageBox displayLoadingInView:weakSelf.view];
    [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        [MessageBox removeLoading];
        if([IoriJsonHelper getErrorCode:request] == 100)
        {
            [weakSelf showMessage:@"删除成功"];
            //删除前页面列表中数据行
            ViewController *parentVC = (ViewController*)weakSelf.parentVC;
            NSMutableArray *tempDataSource = [NSMutableArray arrayWithArray:parentVC.dataSource];
            [tempDataSource removeObjectAtIndex:weakSelf.iRowIndex];
            parentVC.dataSource = tempDataSource;
            [parentVC.tableView deleteSections:[NSIndexSet indexSetWithIndex:weakSelf.iRowIndex] withRowAnimation:UITableViewRowAnimationNone];
            [weakSelf.navigationController popViewControllerAnimated:YES];
        }
        else
        {
            [weakSelf showMessage:[IoriJsonHelper getError:request]];
        }
    } failure:^(YTKBaseRequest *request) {
        [weakSelf showMessage:request.description];
        [MessageBox removeLoading];
    }];
}

- (IBAction)btnFabu_click:(UIButton *)sender
{
    WS(weakSelf);
//    if(self.arrayPic.count == 0)
//    {
//        [self showMessage:@"未设置图片截图"];
//        return;
//    }
    if(weakSelf.selectedChannelID == nil)
    {
        [self showMessage:@"未选择频道！"];
        return;
    }
    self.picContainerView.hidden = YES;
    self.descContainer.hidden = YES;
    if(self.news.art_id == nil)
    {
        //网址新闻
        AddArtApi *api = [AddArtApi new];
        api.admin_id = [UserInfo sharedUser].admin.admin_id;
        api.member_id = api.admin_id;
        api.art_title = self.txtViewTitle.text.length > 0 ?  self.txtViewTitle.text : [weakSelf.webView stringByEvaluatingJavaScriptFromString:@"document.title"] ;
        api.art_img = [weakSelf.arrayImageName componentsJoinedByString:@","];
        api.art_type = @"1";
        api.art_url = weakSelf.webView.request.URL.absoluteString;
        if(weakSelf.selectedChannelID)
        {
            api.channel_id = weakSelf.selectedChannelID;
        }
        api.art_desc= self.txtDesc.text;
        api.art_from = self.txtFrom.text;
        api.art_ori_read = @"0";
        api.art_ori_good = @"0";
        api.art_ori_type = @"0";
        api.hot_id = self.hot;
        api.art_index = self.isShowInHome ? @"1" : @"0";
        api.art_show_time = self.publictime;
        WS(weakSelf);
        [MessageBox displayLoadingInView:weakSelf.view];
        [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
            [MessageBox removeLoading];
            if([IoriJsonHelper getErrorCode:request] == 100)
            {
                weakSelf.news = [NewsEntity yy_modelWithJSON:[IoriJsonHelper getDictForKey:@"art" fromDict:request.responseJSONObject]];
                [weakSelf.webView goBack];
                [weakSelf showMessage:@"发布成功"];
            }
            else
            {
                [weakSelf showMessage:[IoriJsonHelper getError:request]];
            }
        } failure:^(YTKBaseRequest *request) {
            [weakSelf showMessage:[request responseString]];
            [MessageBox removeLoading];
        }];
    }
    else//服务器自有新闻
    {
        void(^addNewsBlock)(void) = ^(void)
        {
            //SetArtApproveStatusApi *api = [SetArtApproveStatusApi new];
            UpdateArtApi *api = [UpdateArtApi new];
            api.admin_id = [UserInfo sharedUser].admin.admin_id;
            api.art_status = @"1";
            api.art_id = weakSelf.news.art_id;
            api.art_star = @"1";
            api.art_show_time = self.publictime;
            api.art_index = self.isShowInHome ? @"1":@"0";
            api.hot_id = self.hot;
            api.art_from = self.txtFrom.text;
            api.art_desc = self.txtDesc.text;
            api.art_title = self.txtViewTitle.text;
            api.channel_id = self.selectedChannelID;
            api.art_img = [weakSelf.arrayImageName componentsJoinedByString:@","];
            [MessageBox displayLoadingInView:weakSelf.view];
            [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request)
             {
                 [MessageBox removeLoading];
                 if([IoriJsonHelper getErrorCode:request] == 100)
                 {
                     [weakSelf endEditStatus];
                     [weakSelf showMessage:@"发布成功"];
                     if([weakSelf.parentVC respondsToSelector:@selector(handleNotification:)])
                     {
                         [weakSelf.parentVC performSelector:@selector(handleNotification:) withObject:nil];
                     }
                     [weakSelf.navigationController popViewControllerAnimated:YES];
                 }
                 else
                 {
                     [weakSelf showMessage:[IoriJsonHelper getError:request]];
                 }
             }
                                             failure:^(YTKBaseRequest *request)
             {
                    [weakSelf showMessage:[request responseString]];
                 [MessageBox removeLoading];
             }];
            
        };
        void(^addNewsPicsBlock)(void) = ^(void)
        {
            SetArtImgApi *setImgApi = [SetArtImgApi new];
            setImgApi.admin_id = [UserInfo sharedUser].admin.admin_id;
            setImgApi.art_id = weakSelf.news.art_id;
            setImgApi.art_img = [self.arrayImageName componentsJoinedByString:@","];
            [MessageBox displayLoadingInView:weakSelf.view];
            [setImgApi startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request)
             {
                 [MessageBox removeLoading];
                 if([IoriJsonHelper getErrorCode:request] == 100)
                 {
                     addNewsBlock();
                 }
                 else
                 {
                     [MessageBox showMsg:[IoriJsonHelper getError:request] viewController:weakSelf];
                 }
             }
                                                   failure:^(YTKBaseRequest *request)
             {
                 [MessageBox removeLoading];
                 [weakSelf showMessage:[request responseString]];
             }];
        };
        addNewsPicsBlock();
    }
}

- (IBAction)btnHot_click:(UIButton *)sender
{
    if(self.news.art_id == nil)
    {
//        [self showMessage:@"该新闻还未发布，不能设置。"];
//        return;
    }
    [self performSegueWithIdentifier:@"segueHot" sender:sender];
}

- (IBAction)btnSnapScreen_click:(UIButton *)sender
{
    self.picContainerView.hidden = !self.picContainerView.hidden;
    self.descContainer.hidden = YES;
}

- (IBAction)btnReply_click:(UIButton *)sender
{
    self.descContainer.hidden = !self.descContainer.hidden;
    self.picContainerView.hidden = YES;
    //self.txtViewTitle.text = [self.webView stringByEvaluatingJavaScriptFromString:@"document.title"];
    CGSize size =  [self.txtViewTitle sizeThatFits:CGSizeMake(self.txtViewTitle.frame.size.width,MAXFLOAT)];
    self.txtViewTitleHeightConstraint.constant = size.height;
    
}

- (IBAction)btnPublishTime_click:(UIButton *)sender
{
    WS(weakSelf);
    if(self.news.art_id == nil)
    {
//        [self showMessage:@"该新闻还未发布，不能设置。"];
//        return;
    }
    IoriDatePicker *picker = [[IoriDatePicker alloc]
                              initWithFrame:CGRectMake(0,
                                                       0,
                                                       weakSelf.view.frame.size.width,
                                                       216)];
    picker.datePickerMode = UIDatePickerModeDateAndTime;
    NSDateFormatter *formater = [NSDateFormatter dateFormatterWithFormat:@"yyyy-MM-dd HH:mm:ss"];
    if(self.publictime.length>0)
    {
        picker.date = [formater dateFromString:self.publictime];
    }
    [picker showDatePickerInViewController:self okCallbackHandler:^(UIDatePicker *datePicker) {
        NSDateFormatter *formater = [NSDateFormatter dateFormatterWithFormat:@"yyyy-MM-dd HH:mm:ss"];
        weakSelf.publictime = [formater stringFromDate:datePicker.date];
        if(weakSelf.news.art_id != nil)
        {
            SetArtTimeApi *timeApi = [SetArtTimeApi new];
            timeApi.admin_id = [UserInfo sharedUser].admin.admin_id;
            timeApi.art_id = weakSelf.news.art_id;
            timeApi.art_show_time = weakSelf.publictime;
            [MessageBox displayLoadingInView:weakSelf.view];
            [timeApi startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
                [MessageBox removeLoading];
                if([IoriJsonHelper getErrorCode:request] == 100)
                {
                    //[weakSelf showMessage:@"成功设置发布时间"];
                }
                else
                {
                    [MessageBox showMsg:[IoriJsonHelper getError:request] viewController:weakSelf];
                }
            } failure:^(YTKBaseRequest *request) {
                [weakSelf showMessage:[request responseString]];
                [MessageBox removeLoading];
            }];
        }
    } cancelCallbackHandler:^{
        ;
    }];
}

- (IBAction)btnChannel_click:(UIButton *)sender
{
    NewsCategoryManagerViewController *vc = [UIStoryboard storyboardWithName:@"NewsCategoryManagerViewController" bundle:nil].instantiateInitialViewController;
    vc.newsCategoryUpdateDelegate = self;
    [self.navigationController pushViewController:vc animated:YES];
}

- (IBAction)btnRadioHome_click:(UIButton *)sender
{
    if(self.news.art_id == nil)
    {
        
    }
    
    [sender setSelected:!sender.isSelected];
    self.isShowInHome = sender.isSelected;
    return;
//    SetArtIndexApi *api = [SetArtIndexApi new];
//    api.admin_id = [UserInfo sharedUser].admin.admin_id;
//    api.art_id = self.news.art_id;
//    if(sender.isSelected)
//    {
//        api.index = @"1";
//    }
//    else
//    {
//        api.index = @"0";
//    }
//    WS(weakSelf);
//    [MessageBox displayLoadingInView:weakSelf.view];
//    [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
//        [MessageBox removeLoading];
//        if([IoriJsonHelper getErrorCode:request] == 100)
//        {
//            [weakSelf showMessage:@"设置成功"];
//        }
//        else
//        {
//            [weakSelf showMessage:[IoriJsonHelper getError:request]];
//        }
//    } failure:^(YTKBaseRequest *request) {
//        [weakSelf showMessage:[request responseString]];
//        [MessageBox removeLoading];
//    }];
}


- (IBAction)btnAddPicture:(UIButton *)sender
{
    PECropViewController *controller = [[PECropViewController alloc] init];
    controller.delegate = self;
    controller.image = [self.webView screenshot];
    
    UIImage *image = controller.image;
    CGFloat width = image.size.width;
    CGFloat height = image.size.height;
    CGFloat length = MIN(width, height);
    controller.imageCropRect = CGRectMake((width - length) / 2,
                                          (height - length) / 2,
                                          length,
                                          length);
    
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:controller];
    [self presentViewController:navigationController animated:YES completion:NULL];
}

- (IBAction)btnOKDesc_click:(UIButton *)sender
{
    self.descContainer.hidden = YES;
    [self.view endEditing:YES];
    if(self.news.art_id == nil)
    {
//        [self showMessage:@"该新闻还未发布，不能设置。"];
//        return;
    }
    if(sender.tag == 1)
    {
        WS(weakSelf);
        if(weakSelf.news.art_id != nil)
        {
            SetArtDescApi *descApi = [SetArtDescApi new];
            descApi.admin_id = [UserInfo sharedUser].admin.admin_id;
            descApi.art_id = weakSelf.news.art_id;
            descApi.art_desc = weakSelf.txtDesc.text;
            [descApi startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
                if([IoriJsonHelper getErrorCode:request] == 100)
                {
                    //[weakSelf showMessage:@"设置短评成功！"];
                }
                else
                {
                    [weakSelf showMessage:[IoriJsonHelper getError:request]];
                }
            } failure:^(YTKBaseRequest *request) {
                [weakSelf showMessage:[IoriJsonHelper getError:request]];
            }];
        }
    }
}

- (IBAction)txtFromDidEndEditing:(UITextField *)sender
{
    WS(weakSelf);
    [sender endEditing:YES];
    if(self.news.art_id == nil)
    {
//        [self showMessage:@"该新闻还未发布，不能设置来源。"];
        return;
    }
    [MessageBox displayLoadingInView:weakSelf.view];
    SetArtFromApi *api = [SetArtFromApi new];
    api.admin_id = [UserInfo sharedUser].admin.admin_id;
    api.art_id = weakSelf.news.art_id;
    api.from = sender.text;
    [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        [MessageBox removeLoading];
        if([IoriJsonHelper getErrorCode:request] == 100)
        {
            weakSelf.news.art_from = sender.text;
            //[weakSelf showMessage:@"设置成功"];
        }
        else
        {
            [weakSelf showMessage:[IoriJsonHelper getError:request]];
        }
    } failure:^(YTKBaseRequest *request) {
       [weakSelf showMessage:[request responseString]];
        [MessageBox removeLoading];
    }];
}

@end
